// Example on page 21. my edition.
// Conclude:
//     1. No need set state like example on page 14. The pupose of
//     state is just to locate the first character of word.

#include <stdio.h>

#define MAXLINE 1000
#define OUT 0 // no need
#define IN 1  // no need

char strnow[MAXLINE];
char strmax[MAXLINE];

int main()
{
    int c;
    int length, longest;
    int i, j, state;

    longest = length = 0;
    i = j = 0;
    state = OUT;

    while ((c = getchar()) != EOF)
    {
        if (c == '\n')
        {
            length = i;
            if (longest < length)
            {
                longest = length;
                for (j = 0; j < longest; j++)
                    strmax[j] = strnow[j];
            }
            state = OUT; //no need
            i = 0;
        }
        else
            state = IN, //no need
                strnow[i] = c,
            i++;
    }

    printf("Longest length is %d\n", longest);
    printf("Longest str is:\n");
    for (j = 0; j < longest; j++)
        printf("%c", strmax[j]);
    printf("\n");

    return 0;
}